/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TestButton.java
 *
 * Created on 2010-apr-22, 13:53:47
 */

package mvc.gui.impl.thumbnailspanel;

import java.awt.event.KeyEvent;

import javax.swing.Icon;

import mvc.core.IMachuPicchu;
import mvc.core.impl.MachuImage;

/**
 * 
 * @author Berget
 */
@SuppressWarnings("serial")
public class ThumbnailButton extends javax.swing.JButton {

	private ThumbnailButtonPresenter presenter;
	private boolean selected = false;
	private MachuImage machuImage;

	/** Creates new form ThumbnailButton */
	public ThumbnailButton(Icon i, IMachuPicchu machuPicchu, MachuImage image) {
		presenter = new ThumbnailButtonPresenter(machuPicchu, this, image);
		this.machuImage = image;
		initComponents();
		this.setIcon(i);
	}
	/*
	 * sets the thumbnail as selected.
	 */
	public void setSelected(){
		this.setBorder(javax.swing.BorderFactory.createLineBorder(
				new java.awt.Color(51, 255, 51), 2));
		selected = true;
	}
	/*
	 * unselects the thumbnail.
	 */
	public void setUnselected(){
		this.setBorder(javax.swing.BorderFactory.createLineBorder(
				new java.awt.Color(0,0,0), 2));
		selected = false;
	}
	/*
	 * returns if the button is selected boolean.
	 * (non-Javadoc)
	 * @see javax.swing.AbstractButton#isSelected()
	 */
	public boolean isSelected(){
		return selected;
	}
	/**
	 * Returns the MachuImage related to Button
	 * @return MachuImage
	 */
	public MachuImage getMachuImage(){
		return machuImage;
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed"
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		setOpaque(false);

		this.setBackground(new java.awt.Color(0, 0, 0));
		this.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/mvc/gui/resources/Blommabakgrund.jpg"))); // NOI18N
		this.setContentAreaFilled(false);
		this.setBorder(javax.swing.BorderFactory.createLineBorder(
				new java.awt.Color(0,0,0), 2));
		this.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				
				
			}
		});
		/*
		 * adds keyListener to the thumbnailButton.
		 */
		this.addKeyListener(new java.awt.event.KeyAdapter() {
			public void keyPressed(java.awt.event.KeyEvent evt) {
				if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
					presenter.removeImage();
				}
			}
		});

	}// </editor-fold>//GEN-END:initComponents

}